package com.framework.modules.guild.dao;

import com.framework.modules.base.entity.UserEntity;
import com.framework.modules.guild.entity.GuildEntity;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 公会表 
 * 
 * @author MIT
 * @email litmiss@gmail.com
 * @date 2020-11-10 12:50:42
 */
public interface GuildDao extends BaseMapper<GuildEntity> {

    @Select("select a.*,b.name as guild_name from tb_user a left join tb_guild b on a.user_id = b.owner_uid " +
            "where a.mobile = #{username} and a.user_id = b.owner_uid limit 0,1")
    Map<String,Object> checkMcnLogin(@Param("username") String username);

    @Select("select a.*,b.nickname,b.avanta from tb_guild_members a  " +
            "left join tb_user_info b on a.member_uid=b.uid " +
            "where a.guild_id=#{guild_id} order by a.id desc limit 0,5")
    List<Map<String,Object>> getNewerGuildMembers(@Param("guild_id") Integer guildId);


    @Select("select * from ( " +
            "select 'total_guild_members' as name , count(1) as `value`from tb_guild_members a  " +
            "where a.guild_id=#{guild_id} " +
            "union " +
            "select 'total_live_seconds' as name,COALESCE(sum(a.total_seconds),0) as `value` from tb_live_history a  " +
            "left join tb_user b on a.uid=b.user_id  " +
            "where b.guild_id = #{guild_id} " +
            "union  " +
            "select 'total_guild_income_money' as name, COALESCE(sum(a.income_money),0) as `value` from tb_guild_income_history a  " +
            "where a.guild_id = #{guild_id} " +
            ") v")
    List<Map<String,Object>> getGuildStatList(Integer guildId);

    @Select("select b.*,a.adddate join_time,a.enddate expire_time,a.member_profit_rate,c.fans_count,d.start_date livetime " +
            "from tb_guild_members a  " +
            "left join tb_user_info b on a.member_uid=b.uid " +
            "left join tb_user_space c on b.uid=c.uid " +
            "left join tb_live_room d on b.uid=d.uid  where a.guild_id=#{guild_id} and a.member_uid=#{uid} limit 0,1")
    Map<String,Object> GetGuildMemberFullInfo(@Param("uid") Integer uid,@Param("guild_id") Integer guildId);
}
